package com.mtons.mblog.web.controller.send;

import io.github.biezhi.ome.OhMyEmail;
import io.github.biezhi.ome.SendMailException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.util.Map;


/**
 * @author lijiayu
 * @date 2020/1/13
 * @description
 */
@Component
@Slf4j
public class RabbitConsumer {

    @RabbitHandler
    @RabbitListener(queues = "direct")
    public void sendEmil(Map<String,String> sendMsg){
        try{
            OhMyEmail.subject(sendMsg.get("title"))
                    .from(sendMsg.get("from"))
                    .to(sendMsg.get("to"))
                    .html(sendMsg.get("text"))
                    .send();
        }catch (SendMailException e) {
            log.error(e.getMessage(), e);
        }
        log.info("email: {} send success", sendMsg.get("to")+"《线程名：》"+Thread.currentThread().getName()+"《线程id:》"+Thread.currentThread().getId());
    }
}
